const mysql = require("mysql");

const connectObj = mysql.createConnection({
    host: "localhost",
    port: "3306",
    user: "root",
    password: "1234",
    database: "u_class"
})

//封装
function query(sql = '') {
    return new Promise(resolve => {
        connectObj.query(sql, (err, result) => {
            if (err) {
                console.log(err);
                return;
            }
            resolve(result)
        })
    })
}
module.exports=query;

/*调用方式
// 案例1 
query(sql).then(result => {
    console.log(result)
})

// 案例2 
async () => {
    let result = await query(sql)
}
*/